#include "header.hpp"
using namespace std;

/* A cinema is releasing a new movie, now there are 100 tickets,
 * sells them by 3 windows, design a program to simulate the condition.
*/
int ticket = 0;
mutex m;

void sellTickets(){
    while(true){
        this_thread::sleep_for(chrono::milliseconds(100));

        m.lock();
        if(ticket < 100){
            ticket++;
            cout << "Window " << this_thread::get_id() << " is selling ticket " << ticket << endl;
            m.unlock();
        } else{
            m.unlock();
            break;
        }
    }
}

void test19(){
    thread t1(sellTickets);
    thread t2(sellTickets);
    thread t3(sellTickets);

    t1.join();
    t2.join();
    t3.join();
}
